package edu.pinkhub.shiro_test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.pinkhub.shiro_test.entity.Depts;
import edu.pinkhub.shiro_test.mapper.DeptsMapper;
import edu.pinkhub.shiro_test.service.DeptsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("deptsService")
public class DeptsServiceImpl extends ServiceImpl<DeptsMapper, Depts> implements DeptsService {

    @Override
    public List<Depts> findParenDept(Integer parentid) {
        QueryWrapper<Depts> wrapper=new QueryWrapper<>();
        wrapper.eq("parentid",parentid);
        List<Depts> DeptsList = this.list(wrapper);
        for (Depts depts : DeptsList) {
            Integer deptid = depts.getDeptid();
            QueryWrapper<Depts> wrapperid=new QueryWrapper<>();
            wrapperid.eq("parentid",deptid);
            List<Depts> deptsList = this.list(wrapperid);
            depts.setChildren(deptsList);
        }
        return DeptsList;
    }
}